import java.util.Scanner;
/**
 * This program allows a user to input two fractions and computes their sum. (Lab #2)
 * 
 * @author Tara Gallagher
 *
 */
public class Lab02 {
	
	 public static void main(String[] args)
	    {
	
	int num1;
	String separator1;
	int den1;
	
	int num2;
	String separator2;
	int den2;
	
    // Read the input.
    Scanner input = new Scanner(System.in);
    System.out.print("Enter first fraction: ");
    num1 = input.nextInt();  
    separator1 = input.next(); 
    	if (separator1.equals("/")||(separator1.equals("//"))) {
        // This format is ideal; proceed with program.
    	}
    	else {
    		System.out.print("Error. Separator must be a /.");
    		System.exit(0);
    	}
    den1 = input.nextInt();  
   
    
    System.out.print("Enter second fraction: ");
    num2 = input.nextInt();  
    separator2 = input.next(); 
    	if (separator2.equals("/")||(separator2.equals("//"))) {
        // This format is ideal; proceed with program.
    	}
    	else {
    		System.out.print("Error. Separator must be a /.");
    		System.exit(0);
    	} 
    den2 = input.nextInt();  
    input.close();
    
    // Compute the sums.
    int numSum;
    int denSumModified;
    int numSumModified;
    numSum = num1 + num2;
    
    if (den1 != den2){ // Adding with different denominators.
    numSumModified = (num1 * den2) + (num2 * den1); // Multiply both sides by the opposite denominator.
    denSumModified = den1 * den2; // Compute common denominator.
    	if (numSumModified == denSumModified){
    		System.out.printf("The sum is 1.");
    	}
    	else System.out.printf("The sum is: %d / %d", numSumModified, denSumModified);
    	}
    
    else if  (den1 == den2 && numSum != den1) // Adding with common denominators.
    System.out.printf("The sum is %d / %d", numSum, den1);
    else 
    System.out.printf("The sum is 1.");
    
	}

}

